#include "GameEngine.h"
#include "Level.h"




using namespace std;
using namespace sf;

map <StateEnum, State*> GameEngine::stateMap;
RenderWindow GameEngine::window(VideoMode(800, 600), "Jin Arena");

GameEngine::GameEngine()
{
	
	
	
	Event event;	
	CharacterManager characterManager;
	Level level(characterManager);
	MusicPlayer musicPlayer;
	auto giveTokenToFunctor = giveTokenTo;	
	SpriteManager SpriteManager;
	RenderingEngine render(window,SpriteManager);
	Clock clock;
	EventParser eventParser(event, window, clock);
	
	

	stateMap[MENU] = new Menu(giveTokenToFunctor, render, eventParser, SpriteManager, musicPlayer);
	stateMap[LOOSEGAME] = new LooseGame(giveTokenToFunctor, render, eventParser, SpriteManager, musicPlayer);
	stateMap[WINGAME] = new WinGame(giveTokenToFunctor, render, eventParser, SpriteManager, musicPlayer);
	stateMap[NEXTLEVEL] = new NextLevel(giveTokenToFunctor, render, eventParser, SpriteManager, musicPlayer);
	stateMap[INGAME] = new InGame(giveTokenToFunctor, render, eventParser, SpriteManager, musicPlayer, level );

	stateMap[MENU]->activate();	
	
}

map <StateEnum, State*> GameEngine::getStateMap()
{
	return stateMap;
}




void GameEngine::giveTokenTo(StateEnum  state)
{
	

	switch (state)
	{
	case WINGAME:
	{
		stateMap[INGAME]->init();
		stateMap[WINGAME]->activate();
		break;
	}
	case NEXTLEVEL:
	{
		stateMap[INGAME]->init();
		stateMap[NEXTLEVEL]->activate();
		break;

	}
	case INGAME:
	{	
		stateMap[INGAME]->activate();
		break;
	}

	case NEW_INGAME:
	{		
		Level::setLevel(1);
		stateMap[INGAME]->init();
		stateMap[NEXTLEVEL]->activate();
		break;
	}

	case MENU:
	{		
		stateMap[MENU]->activate();
		break;
	}
	case LOOSEGAME:
	{			
		
		stateMap[INGAME]->init();
		stateMap[LOOSEGAME]->activate();
		break;
	}

	case CLOSEGAME:
	{
		 window.close();
		 break;
	}
	default:
	{
		stateMap[state]->activate();
		break;
	}
	}
	


	
}

